Gnc.EmployeeAutoSelect = function () {
    Gnc.EmployeeAutoSelect.superclass.constructor.call(this);
    this.set({
        border: 1,
        emptyText: '按账号模糊搜索',
        valueField:'Id',
        textField:'Name',
        delay:1000,
        popupEmptyText:'账号不存在',
        showClose:true,
        width:'100%'
    });
};
mini.extend(Gnc.EmployeeAutoSelect, mini.AutoComplete, {
    uiCls: "gnc-employeeautoselect",
    /*url: bootPATH + GNC.Uri.GetEmployeeByAccount.replace('js=1', 'js=2') ,*/
    url: bootPATH + GNC.Uri.GetEmployeeByAccount,
    autoselectedItem: null,    
    autoLoad: false,
    searchField:'Account',
    _create: function () {
        Gnc.EmployeeAutoSelect.superclass._create.call(this);
        this.on('valuechanged',function(record){
            var rec = record.selected;
            if(!rec){
                mini.alert('该账号不存在，请重新输入', '警告');
                this.setNameValue('','');
                return;
            }
            var name = record.selected.Name + '[' + record.selected.Account + ']';
            this.setNameValue(name,record.selected.Id);
            this.autoselectedItem = rec;
        	this.fire('employeeAutoSelected',this.autoselectedItem);
        },this);
        this.on('closeclick',function(){
            this.setNameValue('','');
            this.fire('employeeAutoCleared');
        },this);
        this.on('drawcell',function(e){
            var record=e.record;
            var DepartmentName='';
            if(!mini.isEmpty(record.Department)&& !mini.isEmpty(record.Department.Name))
                DepartmentName = record.Department.Name;
            e.cellHtml = record.Name + ' ' + record.Account + ' ( ' + DepartmentName + ' )';
        },this);
    },
    setNameValue:function(name,value){
        this.setValue(value);
        this.setText(name);
    },
    reload:function(){
        this.setUrl(this.url);
        this.loaded = true;
    }
});
mini.regClass(Gnc.EmployeeAutoSelect, "Gnc.EmployeeAutoSelect");